package com.lams.action.archive;

import java.util.Map;

import com.lams.action.SubAction;
import com.lams.service.archive.ISchoolFacade;
import com.lams.util.ResultEntity;
import com.opensymphony.xwork2.ActionContext;

import static com.lams.util.ViewParamsUtil.*;

public class SchoolAction extends SubAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 92330686210453819L;
	private ISchoolFacade schoolF;
	/**
	 * 查询学校
	 * 
	 * @return
	 */
	public String query() {
		Map params = ActionContext.getContext().getParameters();
//		String qrySql = QueryUtils.getSqlBySqlCode("QUERYSCHOOLS", params);
//		List list = QueryUtils.executeQuery(this.getStart(), this.getLimit(), qrySql);
		ResultEntity result = schoolF.querySchool(this.getStart(), this.getLimit(), params);
//		result.setTotalCount(list.size());
		result.setSuccess(true);
//		result.setData(list);
		result.setLimit(this.getLimit());
		result.setStart(this.getStart());
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public String saveOrUpdate() {
		Map params = ActionContext.getContext().getParameters();
		ResultEntity result = schoolF.saveOrUpdate(params);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public String delete() {
		ResultEntity result = new ResultEntity();
		String school_id = getParam("SCHOOL_ID");
		if (school_id == null || school_id.trim().equals("")) {
			result.setSuccess(true);
			result.setMessage("未选中记录");
			return SUCCESS;
		}
		boolean f = schoolF.delete(school_id);
		result.setMessage(f?"删除成功":"删除失败");
		result.setSuccess(f);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public ISchoolFacade getSchoolF() {
		return schoolF;
	}

	public void setSchoolF(ISchoolFacade schoolF) {
		this.schoolF = schoolF;
	}
	
}
